package com.javabi.boardgame.model.board.grid;

import com.javabi.boardgame.model.board.ILocation;

/**
 * An immutable grid location.
 */
public class GridLocation implements ILocation {

	public static int convert(char character, int maxValue) {
		character = Character.toUpperCase(character);
		int value = (character - 'A') + 1;
		if (value < 1 || value > maxValue) {
			throw new IllegalArgumentException("Invalid character: '" + character + "'");
		}
		return value;
	}

	private final int x;
	private final int y;

	public GridLocation(int x, int y) {
		if (x < 1) {
			throw new IllegalArgumentException("x=" + x);
		}
		if (y < 1) {
			throw new IllegalArgumentException("y=" + y);
		}
		this.x = x;
		this.y = y;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

}
